1
|
|
|
/** |
2
|
|
|
dark |
3
|
|
|
Component that handles dark matter and second prestige logic. |
4
|
|
|
It handles dark matter production and dark upgrades. |
5
|
|
|
A second prestige resets the progress of all elements with exotic |
6
|
|
|
matter and produces dark matter. |
7
|
|
|
|
8
|
|
|
@namespace Components |
9
|
|
|
*/ |
10
|
|
|
'use strict'; |
11
|
|
|
|
12
|
|
|
angular.module('game').component('dark', { |
13
|
|
|
templateUrl: 'views/dark.html', |
14
|
|
|
controller: ['state', 'format', 'visibility', 'upgrade', 'data', 'util', dark], |
15
|
|
|
controllerAs: 'ct' |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
function dark(state, format, visibility, upgrade, data, util) { |
19
|
|
|
let ct = this; |
20
|
|
|
ct.state = state; |
21
|
|
|
ct.data = data; |
22
|
|
|
ct.util = util; |
23
|
|
|
ct.format = format; |
24
|
|
|
|
25
|
|
|
ct.darkProduction = function() { |
26
|
|
|
let production = 0; |
27
|
|
|
for (let element in data.elements) { |
28
|
|
|
let exotic = data.elements[element].exotic; |
29
|
|
|
if (!state.player.resources[exotic].unlocked) { |
30
|
|
|
continue; |
31
|
|
|
} |
32
|
|
|
production += Math.floor(Math.max(0, Math.log(state.player.resources[exotic].number))); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return production; |
36
|
|
|
}; |
37
|
|
|
|
38
|
|
|
ct.darkPrestige = function() { |
39
|
|
|
let resources = state.player.resources; |
40
|
|
|
let production = ct.darkProduction(); |
41
|
|
|
|
42
|
|
|
resources.dark_matter.number += production; |
43
|
|
|
resources.dark_matter.unlocked = true; |
44
|
|
|
|
45
|
|
|
for(let key in data.elements){ |
46
|
|
|
let element = data.elements[key]; |
47
|
|
|
state.player.resources[element.exotic].number = 0; |
48
|
|
|
for(let up in data.exotic_upgrades){ |
49
|
|
|
state.player.exotic_upgrades[key][up] = false; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
for(let slot of state.player.element_slots){ |
53
|
|
|
if(!slot){ |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
upgrade.resetElement(state.player, slot.element); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
for(let i in state.player.element_slots){ |
60
|
|
|
state.player.element_slots[i] = null; |
61
|
|
|
} |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
ct.buyDarkUpgrade = function(name) { |
65
|
|
|
let upgrades = state.player.dark_upgrades; |
66
|
|
|
let price = data.dark_upgrades[name].price; |
67
|
|
|
let currency = 'dark_matter'; |
68
|
|
|
upgrade.buyUpgrade(state.player, |
69
|
|
|
upgrades, |
70
|
|
|
data.dark_upgrades[name], |
71
|
|
|
name, |
72
|
|
|
price, |
73
|
|
|
currency); |
74
|
|
|
}; |
75
|
|
|
|
76
|
|
|
ct.visibleDarkUpgrades = function() { |
77
|
|
|
return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0); |
78
|
|
|
}; |
79
|
|
|
|
80
|
|
|
// here we receive not the name of the element, but the index in the element_slots |
81
|
|
|
function isDarkUpgradeVisible(name, index) { |
82
|
|
|
return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name]); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|